package sessionBean;

import java.util.List;

import interfaceBeanRemote.sessionClubAmisRemote;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import entityBean.Club;
import entityBean.Clubami;

/**
 * Session Bean implementation class sessionClubAmis
 */
@Stateless
public class sessionClubAmis implements sessionClubAmisRemote {

	@PersistenceContext(unitName = "EJB3_Entity")
	private EntityManager em;

	@PostConstruct
	public void init() {
		System.out.println("calling init method");
	}

	@PreDestroy
	public void cleanup() {
		System.out.println("calling cleanup method");
	}

	/**
	 * Default constructor.
	 */
	public sessionClubAmis() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void addClubAmi(Clubami clubAmi) {
		// TODO Auto-generated method stub
		em.persist(clubAmi);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Integer> getClubAmis(int id_club) {
		// TODO Auto-generated method stub
		Query query = em
				.createQuery("SELECT c.idDuClubAmis FROM Clubami  AS c where c.club = " + id_club
						+ " ORDER BY c.idDuClubAmis ASC");
		return (List<Integer>) query.getResultList();
	}


	@Override
	public void refresh(Clubami ca) {
		// TODO Auto-generated method stub
		em.refresh(ca);
	}

	@Override
	public void flush() {
		// TODO Auto-generated method stub
		em.flush();

	}

}
